package com.example.fireassistant_server.controller;

import com.example.fireassistant_server.dto.wechat.WechatUserSearchFilter;
import com.example.fireassistant_server.mapper.WechatUserMapper;
import com.example.fireassistant_server.service.WechatUserService;
import com.example.fireassistant_server.vo.WechatUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


//超级管理员控制权限
@RestController
@RequestMapping("/permission")
@CrossOrigin
public class PermissionController {

    WechatUserService wechatUserService;

    WechatUserMapper wechatUserMapper;


    @PostMapping("/wechat/search")
    @PreAuthorize("hasRole('ROLE_SUPER_ADMIN') or hasRole('ROLE_STATION_ADMIN')")
    Page<WechatUserVo> search(@Validated @RequestBody WechatUserSearchFilter filter) {
        return wechatUserService.search(filter).map(wechatUserMapper::toVo);
    }



    @Autowired
    public void setWechatUserService(WechatUserService wechatUserService) {
        this.wechatUserService = wechatUserService;
    }

    @Autowired
    public void setWechatUserMapper(WechatUserMapper wechatUserMapper) {
        this.wechatUserMapper = wechatUserMapper;
    }
}
